<!-- 发票类型控件 -->
<template>
  <a-space direction="vertical" style="width: 100%">
    <a-select
      v-model="form"
      :disabled="props.disabled"
      :placeholder="form.placeholder ? form.placeholder : '请选择发票类型'"
      @change="selected"
    >
      <a-option v-for="item in data.list" :key="item.id" :value="item.id">{{
        item.typeName
      }}</a-option>
    </a-select>
  </a-space>
</template>

<script lang="ts" setup>
  import { reactive, computed, ref } from 'vue';
  import { GetSetInvoiceInfo } from '@/api/order-management/returned-management/base-setting';
  import miiter from '@/utils/mitt';

  const props = withDefaults(
    defineProps<{
      props: { [propName: string]: any };
      name?: string;
      required?: boolean;
      disabled?: boolean;
      oneValue: any;
      regex?: {
        [name: string]: {
          role: any;
          name: any;
        };
      };
    }>(),
    { oneValue: null }
  );

  const emit = defineEmits(['update:oneValue']);
  const form = computed({
    get() {
      return Number(props.oneValue);
    },
    set(val) {
      emit('update:oneValue', val);
    },
  });
  interface Item {
    id: number;
    name: string;
    [name: string]: string | number;
  }
  interface DataType {
    list: Item[];
  }
  const data = reactive<any>({ list: [] });
  // 获取发票类型数据
  const getData = async () => {
    try {
      data.list = await GetSetInvoiceInfo();
    } catch (error: unknown) {
      console.log(error);
    }
    // TODO:没有发票类型接口
    // let res = await GetPersonnelinformation({ pageIndex: 0, pageSize: 9999 })
    // data.list = res.data
    // data.list.unshift(option)
  };
  getData();

  // 获取选中的数据
  const selected = (id: number) => {
    const selectedItem = data.list.find((item: any) => item.id === id);
    miiter.emit('invoiceTypeRefresh', selectedItem);
  };
</script>

<style scoped lang="less"></style>
